﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using Bortosky.Google.Visualization;
using Icoders.MarketTracker.Reports.Lib.Repository.Transactions;
using Icoders.MarketTracker.Reports.Lib.Util;
using Icoders.MarketTracker.Web.Lib.Security;
using Icoders.MarketTracker.Web.Lib.Services;
using Icoders.MarketTracker.Web.Lib.Util.Helper;

namespace Icoders.MarketTracker.Web.Controllers
{    [CustomAuthorize]
    public class BATController : Controller
    {
        //
        // GET: /BAT/
        private IDashboardReportService _dashboardReportService;
    private IDropDownService _dropDownService;

    public BATController(IDashboardReportService dashboardReportService, IDropDownService dropDownService)
    {
        _dashboardReportService = dashboardReportService;
        _dropDownService = dropDownService;
    }

    public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult GetSalePerSkuPerAreaDashBoard()
        {

            ContentResult result = new ContentResult();
            result.ContentType = "application/text";
            result.ContentEncoding = Encoding.UTF8;
            result.Content = null;
            DataTable data = _dashboardReportService.GetSalePerSkuPerAreaDashBoard(Common.GetClientIdFromCookies()).ToList().ToDataTable();
            DataTable data2 = PivotHelper.Pivot(data, "Area", "Product", "Quantity");

            result.Content = new GoogleDataTable(data2).GetJson();

            return result;

        }
        [HttpPost]
        public ActionResult GetSalePerSkuPerCityDashBoard()
        {

            ContentResult result = new ContentResult();
            result.ContentType = "application/text";
            result.ContentEncoding = Encoding.UTF8;
            result.Content = null;
            DataTable data = _dashboardReportService.GetSalePerSkuPerCityDashBoard(Common.GetClientIdFromCookies()).ToList().ToDataTable();
            DataTable data2 = PivotHelper.Pivot(data, "City", "Product", "Quantity");

            result.Content = new GoogleDataTable(data2).GetJson();

            return result;

        }
        [HttpPost]
        public ActionResult GetSkuVolumeDashBoard()
        {

            ContentResult result = new ContentResult();
            result.ContentType = "application/text";
            result.ContentEncoding = Encoding.UTF8;
            result.Content = null;
            DataTable data = _dashboardReportService.GetSkuVolumeDashBoard(Common.GetClientIdFromCookies()).ToList().ToDataTable();
            //DataTable data2 = PivotHelper.Pivot(data, "Area", "Product", "Quantity");

            result.Content = new GoogleDataTable(data).GetJson();

            return result;

        }
        [HttpPost]
        public ActionResult GetSkuVolumeByCityDashBoard(int cityId)
        {

            ContentResult result = new ContentResult();
            result.ContentType = "application/text";
            result.ContentEncoding = Encoding.UTF8;
            result.Content = null;
            DataTable data = _dashboardReportService.GetSkuVolumeByCityDashBoard(Common.GetClientIdFromCookies(), cityId).ToList().ToDataTable();
            //DataTable data2 = PivotHelper.Pivot(data, "Area", "Product", "Quantity");

            result.Content = new GoogleDataTable(data).GetJson();

            return result;

        }
        [HttpPost]
        public ActionResult GetDailySkuVolumeDashBoard()
        {

            ContentResult result = new ContentResult();
            result.ContentType = "application/text";
            result.ContentEncoding = Encoding.UTF8;
            result.Content = null;
            DataTable data = _dashboardReportService.GetDailySkuVolumeDashBoard(Common.GetClientIdFromCookies()).ToList().ToDataTable();
            //DataTable data2 = PivotHelper.Pivot(data, "Area", "Product", "Quantity");

            result.Content = new GoogleDataTable(data).GetJson();

            return result;

        }
        public ActionResult SalebyProduct()
        {
            ViewBag.Cities = _dashboardReportService.GetCityWithData(Common.GetClientIdFromCookies());
            return View();
        }
        public ActionResult CallEfficiency()
        {
            ViewBag.Cities = _dashboardReportService.GetCityWithData(Common.GetClientIdFromCookies());
            return View();
        }
        public ActionResult CallEffectiveness()
        {
            ViewBag.Cities = _dashboardReportService.GetCityWithData(Common.GetClientIdFromCookies());
            return View();
        }
        [HttpPost]
        public ActionResult GetCallageEffectivenessByCityDashBoard(int cityId)
        {

            ContentResult result = new ContentResult();
            result.ContentType = "application/text";
            result.ContentEncoding = Encoding.UTF8;
            result.Content = null;
            DataTable data = _dashboardReportService.GetCallageEffectivenessByCityDashBoard(Common.GetClientIdFromCookies(), cityId).ToList().ToDataTable();
            //DataTable data2 = PivotHelper.Pivot(data, "Area", "Product", "Quantity");

            result.Content = new GoogleDataTable(data).GetJson();

            return result;

        }
        [HttpPost]
        public ActionResult GetCallageByCityDashBoard(int cityId)
        {

            ContentResult result = new ContentResult();
            result.ContentType = "application/text";
            result.ContentEncoding = Encoding.UTF8;
            result.Content = null;
            DataTable data = _dashboardReportService.GetCallageByCityDashBoard(Common.GetClientIdFromCookies(), cityId).ToList().ToDataTable();
            //DataTable data2 = PivotHelper.Pivot(data, "Area", "Product", "Quantity");

            result.Content = new GoogleDataTable(data).GetJson();

            return result;

        }

    }
}
